/************************************************************************
 * @user wxl
 * @date 2016/2/28
 * @description 导航插件
 *************************************************************************
 * @copyright by wh  可以提供开源，但如果引用代码需标明出处
 ************************************************************************/
;(function(NS,$){
    NS.Navigation = function(data){
        var navMount = data.element;
        var navHtml = "<div class='ui-nav'></div>";
        var nav = $(navHtml).appendTo($(navMount));
        var navItemHtml = "<ul class='ui-nav-item'></ul>";
        var navItem = $(navItemHtml).appendTo(nav);
        var points = new Array();
        var NavWidget = function(){
            var selectStep =  data.selectStep ? data.selectStep : 0;
            var steps =  data.steps ? data.steps : ["step1", "step2", "step3", "step4", "step5"];
        }

        NavWidget.prototype.setSelectStep = function(step){
            if(step < 0 || step > data.steps.length - 1)
                return;
            for(var index in points){
                if(step == index){
                    points[index].addClass('ui-nav-point-selected');
                    points[index].removeClass('ui-nav-point-not-selected');
                }else{
                    points[index].addClass('ui-nav-point-not-selected');
                    points[index].removeClass('ui-nav-point-selected');
                }
            }
        }

        var navWidgetInstance = new NavWidget();
        var _createNav = function(){
            NS.widgetMgr.registry(navMount.id,navWidgetInstance);
            var steps =  data.steps ? data.steps : ["step1", "step2", "step3", "step4", "step5"];
            for(var index in steps){
                var navItemChildHtml = "<li class='ui-nav-item-child'>"+steps[index]+"</li>";
                var point = $(navItemChildHtml).appendTo(navItem);
                points.push(point);
            }
            _bind();
        }

        var _bind = function(){
            $('.ui-nav-item').children().each(function(index){
                navWidgetInstance.setSelectStep(0);
                $(this).on('click',function(){
                    navWidgetInstance.setSelectStep(index);
                });
            });
        }
        _createNav();

    }
})(wh.ui,jQuery);